home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / network / lattice / portlib.lzh / PORTLIB / STRCASEC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-09  |  1.2 KB  |  45 lines

  1. /* derived from strcmp from Henry Spencer's stringlib */
  2. /* modified by ERS */
  3. /* i-changes by Alexander Lehmann */
  4. /* case-changes by Kay Roemer */
  5.  
  6. #include <string.h>
  7. #include <ctype.h>
  8.  
  9. /*
  10.  * strcasecmp - compare string s1 to s2 without case sensitivity
  11.  *              result is equivalent to strcmp(strlwr(s1),strlwr(s2)),
  12.  *              but doesn't change anything
  13.  */
  14.  
  15. int                             /* <0 for <, 0 for ==, >0 for > */
  16. strcasecmp(scan1, scan2)
  17. register const char *scan1;
  18. register const char *scan2;
  19. {
  20.         register char c1, c2;
  21.  
  22.         if (!scan1)
  23.                 return scan2 ? -1 : 0;
  24.         if (!scan2) return 1;
  25.  
  26.         do {
  27.                 c1 = *scan1++; c1=tolower(c1);
  28.                 c2 = *scan2++; c2=tolower(c2);
  29.         } while (c1 && c1 == c2);
  30.  
  31.         /*
  32.          * The following case analysis is necessary so that characters
  33.          * which look negative collate low against normal characters but
  34.          * high against the end-of-string NUL.
  35.          */
  36.         if (c1 == c2)
  37.                 return(0);
  38.         else if (c1 == '\0')
  39.                 return(-1);
  40.         else if (c2 == '\0')
  41.                 return(1);
  42.         else
  43.                 return(c1 - c2);
  44. }
  45.